package insight.web.controllers;

import insight.miescor.db.DBManager;
import insight.primavera.common.P6helper;

import java.io.BufferedReader;
import java.io.IOException;

import javax.servlet.http.HttpServletRequest;

import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class GenericController {
	@Autowired
	protected P6helper helper;
	@Autowired
	protected DBManager dbManager;

	public static JSONObject readJSON(HttpServletRequest request) throws IOException {
		StringBuilder sb = new StringBuilder();
		BufferedReader br = request.getReader();
		String str;
		while ((str = br.readLine()) != null) {
			sb.append(str);
		}
		try {
			JSONObject jObj = new JSONObject(sb.toString());
			return jObj;
		} catch (JSONException e) {
			e.printStackTrace();
			return null;
		}
	}

	public P6helper getHelper() {
		return helper;
	}

	public void setHelper(P6helper helper) {
		this.helper = helper;
	}

	public DBManager getDbManager() {
		return dbManager;
	}

	public void setDbManager(DBManager dbManager) {
		this.dbManager = dbManager;
	}
}
